package com.nariano.server.domain.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

@Entity
@Table(name="population")
public class Population implements Serializable{
    
	@Id
	@GeneratedValue
	@Column(name="population_id")
    private Integer id;
    
    @Column(name="number")
    private int number;
    
    @Column(name="user_id")
    Integer userId;

    @Column(name="population_type_id")
    private String hibernateType;
    
    @Column(name="position_area")
    Integer positionArea;
    
    private Population() {
    }
    
    public Population(Integer userId, PopulationType type) {
        this(userId, type, 0);
    }

    public Population(Integer userId, PopulationType type, int number) {
    	this.userId = userId;
        this.hibernateType = type.getId();
        this.number = number;
	}

	public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public PopulationType type() {
        return PopulationType.resolve(hibernateType);
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }
    
    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer user) {
        userId = user;
    }


    public Integer getPositionArea() {
		return positionArea;
	}

    public void setPositionArea(Integer area) {
		this.positionArea = area;
	}

	@Override
    public String toString() {
    	return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE); 
    }

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((hibernateType == null) ? 0 : hibernateType.hashCode());
		result = prime * result + ((userId == null) ? 0 : userId.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Population other = (Population) obj;
		if (hibernateType == null) {
			if (other.hibernateType != null)
				return false;
		} else if (!hibernateType.equals(other.hibernateType))
			return false;
		if (userId == null) {
			if (other.userId != null)
				return false;
		} else if (!userId.equals(other.userId))
			return false;
		return true;
	}

    
    
    

}
